import request from '@/utils/request'

/**
 * 创建订单
 * @returns
 */
export function createOrder() {
    return request('/member/order/pre', 'get')
}

/**
 * 添加收货地址
 * @param {Object} from
 * @returns
 */
export function addAddress(form) {
    return request('/member/address', 'post', form)
}
/**
 * 删除收货地址
 * @param {*} id 地址id
 * @returns
 */
export function deleteAddress(id) {
    return request(`/member/address/${id}`, 'delete')
}
/**
 * 修改收货地址
 * @param {Object} form
 * @returns
 */
export function updateAddress(form) {
    return request(`/member/address/${form.id}`, 'put', form)
}
/**
 * 提交订单
 * @param {*} params
 * @returns
 */
export function submitOrder(params) {
    return request(`/member/order/`, 'post', params)
}
/**
 * 获取订单详细数据
 * @param {*} orderId
 * @returns
 */
export function findOrderDetail(orderId) {
    return request(`/member/order/` + orderId, 'get')
}

/**
 * 查询订单列表
 * @param {Number} orderState - 订单状态，1为待付款、2为待发货、3为待收货、4为待评价、5为已完成、6为已取消，未传该参数或0为全部
 * @param {Number} page - 页码
 * @param {Number} pageSize - 每页条数
 * @returns
 */
export const findOrderList = ({ orderState, page, pageSize }) => {
    return request('/member/order', 'get', { orderState, page, pageSize })
}

/**
 * 取消订单
 * @param {String} orderId - 订单ID
 * @param {String} cancelReason - 取消原因
 * @returns Promise
 */
export const cancelOrder = (orderId, cancelReason) => {
    return request(`/member/order/${orderId}/cancel`, 'put', { cancelReason })
}

/**
 * 删除订单
 * @param {Array<string>} ids - 删除订单，id集合
 * @returns
 */
export const delteOrder = (ids) => {
    return request('/member/order', 'delete', { ids })
}

/**
 * 确认收货
 * @param {String} id 订单id 
 * @returns 
 */
export const confirmOrder = (id) => {
    return request(`/member/order/${id}/receipt`, 'put')
}

/**
 * 查看物流
 * @param {*} id 订单id 
 * @returns 
 */
export const lookLogistics = (id) => {
    return request(`/member/order/${id}/logistics`, 'get')
}